package com.ruoyi.life.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.life.domain.SysBillAccount;
import com.ruoyi.life.service.ISysBillAccountService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 收款账户Controller
 *
 * @author yy
 * @date 2021-12-02
 */
@Api(tags = " 收款账户")
@RestController
@RequestMapping("/sysBillAccount")
public class SysBillAccountController extends BaseController {
    @Autowired
    private ISysBillAccountService sysBillAccountService;

    /**
     * 查询收款账户列表
     */
    @ApiOperation(value="查询收款账户列表", notes="查询收款账户列表")
    @PreAuthorize(hasPermi = "life:sysBillAccount:list")
    @GetMapping("/list")
    public TableDataInfo list(SysBillAccount sysBillAccount) {
        startPage();
        List<SysBillAccount> list = sysBillAccountService.selectSysBillAccountList(sysBillAccount);
        return getDataTable(list);
    }

    /**
     * 导出收款账户列表
     */
    @ApiOperation(value="导出收款账户列表", notes="导出收款账户列表")
    @PreAuthorize(hasPermi = "life:sysBillAccount:export")
    @Log(title = "收款账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBillAccount sysBillAccount) throws IOException {
        List<SysBillAccount> list = sysBillAccountService.selectSysBillAccountList(sysBillAccount);
        ExcelUtil<SysBillAccount> util = new ExcelUtil<SysBillAccount>(SysBillAccount.class);
        util.exportExcel(response, list, "收款账户数据");
    }
    /**
     * 获取收款账户详细信息
     */
    @ApiOperation(value="获取收款账户详细信息", notes="获取收款账户详细信息")
    @PreAuthorize(hasPermi = "life:sysBillAccount:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(sysBillAccountService.selectSysBillAccountById(id));
    }

    /**
     * 新增收款账户
     */
    @ApiOperation(value="新增收款账户", notes="新增收款账户")
    @PreAuthorize(hasPermi = "life:sysBillAccount:add")
    @Log(title = "收款账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBillAccount sysBillAccount) {
        if (sysBillAccountService.insertSysBillAccount(sysBillAccount)>0){
            return AjaxResult.success("新增成功");
        }else {
            return AjaxResult.error("新增失败,存在相同账户名");
        }
    }

    /**
     * 修改收款账户
     */
    @ApiOperation(value="修改收款账户", notes="修改收款账户")
    @PreAuthorize(hasPermi = "life:sysBillAccount:edit")
    @Log(title = "收款账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBillAccount sysBillAccount) {
        if (sysBillAccountService.updateSysBillAccount(sysBillAccount)>0){
            return AjaxResult.success("修改成功");
        }else {
            return AjaxResult.error("修改失败,存在相同账户名");
        }
    }

    /**
     * 删除收款账户
     */
    @ApiOperation(value="删除收款账户", notes="删除收款账户")
    @ApiImplicitParam(name = "ids", value = "收款账户ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "life:sysBillAccount:remove")
    @Log(title = "收款账户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(sysBillAccountService.deleteSysBillAccountByIds(ids));
    }
}
